import { fetchChannelAPI } from "@/apis/home";
import type { ChannelItem } from "@/apis/home";
import { useEffect, useState } from "react";

function useFetchChannels() {
  const [channels, setChannels] = useState<ChannelItem[]>([]);
  useEffect(() => {
    async function getChannels() {
      try {
        const { data } = await fetchChannelAPI();
        setChannels(data.data.channels);
      } catch (error) {
        throw new Error("fetch channels error");
      }
    }
    getChannels();
  }, []);
  return {
    channels,
  };
}

export { useFetchChannels };
